Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The dezalgo npm package ensures that a callback is always called asynchronously, and not in the same tick of the event loop that it was added in, even if it is already complete. This is useful for preventing stack overflows and ensuring consistent asynchronous behavior.
Ensuring asynchronous callback execution
This feature wraps a callback function to ensure that it is always called on the next tick of the event loop, even if it could be called immediately.
const dezalgo = require('dezalgo')
const callback = dezalgo((err, data) => {
// This will always run asynchronously
console.log('Callback called asynchronously')
})
// Even if we call it synchronously, it will be deferred
callback(null, 'some data')
This package is similar to dezalgo in that it defers the execution of callbacks to the next tick of the event loop. It also allows for passing arguments to the callback, similar to how 'Function.prototype.apply' works.
The setimmediate package provides a way to execute a function asynchronously as soon as possible, but after the current event loop tick. It is similar to dezalgo but uses a different mechanism (setImmediate) which is a standard part of the Node.js and browser environments.
The async package offers a wide range of functions for working with asynchronous code. One of its utilities, 'async.nextTick', is similar to dezalgo in that it ensures a callback is called on the next tick of the event loop.
Contain async insanity so that the dark pony lord doesn't eat souls
See this blog post.
Pass a callback to dezalgo
and it will ensure that it is always
called in a future tick, and never in this tick.
var dz = require('dezalgo')
var cache = {}
function maybeSync(arg, cb) {
cb = dz(cb)
// this will actually defer to nextTick
if (cache[arg]) cb(null, cache[arg])
fs.readFile(arg, function (er, data) {
// since this is *already* defered, it will call immediately
if (er) cb(er)
cb(null, cache[arg] = data)
})
}
FAQs
Contain async insanity so that the dark pony lord doesn't eat souls
We found that dezalgo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.